<?php
namespace Home\Model;
use Think\Model;

class CollectModel extends Model
{
    protected $trueTableName ='collects';
    
    public function collectsAdd()
    {
        $type = I('post.type');
        $description = I('post.description', '');
        $path = I('post.path','');
        $contact_name= I('post.contact_name');
        $phone = I('post.phone');
        $seat_machine = I('post.seat_machine','');
        $email = I('post.email');

        if (empty($type)) {
            $this->error = '投资类型必须选择';
            return false;
        }
        if (empty($contact_name)) {
            $this->error = '联系人必填';
            return false;
        }
        if (empty($phone)) {
            $this->error = '手机号必填';
            return false;
        }
        if (strlen($phone) != '11') {
            $this->error = '手机号格式不正确';
            return false;
        }
        if (empty($email)) {
            $this->error = '邮箱必填';
            return false;
        }

        $this->type = $type;
        $this->description = $description;
        $this->path = $path;
        $this->contact_name= $contact_name;
        $this->phone = $phone;
        $this->seat_machine = $seat_machine;
        $this->email = $email;
        $this->collected_at = time();

        if ($this->add()) {
            return true;
        } else {
            return false;
        }
    }
}